/********************************************************************
	created:	30:9:2007   21:18
	author:		tiamo
	purpose:	flush
*********************************************************************/

#include "stdafx.h"

// flush
NTSTATUS AppleKeyboardFlush(__in PDEVICE_OBJECT pDeviceObject,__in PIRP pIrp)
{
	NTSTATUS statusRet = STATUS_SUCCESS;
	CDeviceExtension* pDevExt = static_cast<CDeviceExtension*>(pDeviceObject->DeviceExtension);

	AppleDebugPrint(DBGLEVEL_INFO,"Enter AppleKeyboardFlush %p,%p\n",pDeviceObject,pIrp);

	AppleDbgBreakPoint();

	statusRet = IoAcquireRemoveLock(&pDevExt->m_removeLock,pIrp);
	if(NT_SUCCESS(statusRet))
	{
		IoCopyCurrentIrpStackLocationToNext(pIrp);
		PIO_STACK_LOCATION pIrpSp = IoGetNextIrpStackLocation(pIrp);
		pIrpSp->MajorFunction = IRP_MJ_DEVICE_CONTROL;
		pIrpSp->Parameters.DeviceIoControl.IoControlCode = IOCTL_HID_FLUSH_QUEUE;
		statusRet = IoCallDriver(pDevExt->m_pLowerDevice,pIrp);
		IoReleaseRemoveLock(&pDevExt->m_removeLock,pIrp);
	}
	else
	{
		pIrp->IoStatus.Status = statusRet;
		IoCompleteRequest(pIrp,IO_NO_INCREMENT);
	}

	AppleDebugPrint(DBGLEVEL_INFO,"Leave AppleKeyboardFlush 0x%08x\n",statusRet);

	return statusRet;
}